<template>
  <div>
    <el-table v-loading="loading" :data="orderList">
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column label="订单编号" align="center" prop="orderSnId" />
      <!-- <el-table-column label="总价" align="center" prop="servicePrice" /> -->
      <el-table-column label="服务类型" align="center">
        <template slot-scope="scope">
          <p>{{  scope.row.serviceTypeName }}</p>
        </template>
      </el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime" />
      <!-- <el-table-column label="是否加急" align="center">

        <template slot-scope="scope">
          <p>{{ urgent[scope.row.urgent] }}</p>
        </template>
      </el-table-column> -->
      <el-table-column label="订单状态" align="center">

        <template slot-scope="scope">
          <p>{{ orderStatus[scope.row.orderStatus] }}</p>
        </template>
      </el-table-column>
      <el-table-column label="服务状态" align="center">

        <template slot-scope="scope">
          <p>{{ serviceStatus[scope.row.serviceStatus] }}</p>
        </template>
      </el-table-column>
      <el-table-column label="处理人" align="center" prop="processedName" />
      <el-table-column label="处理日期">

        <template slot-scope="scope" v-if="scope.row.parseTime">
          <p>{{ timestampToDate(scope.row.parseTime) }}</p>
        </template>
      </el-table-column>
      <el-table-column label="科藤备注" align="center" prop="ktRemark" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"

       :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>

import { listOrderByUserId } from '../../../api/order/order'
import {
  ASSOC_SEARCH_BY_USER,
  ORDER_STATUS,
  PROPS_ID,
  SERVICE_STATUS,
  URGENT,
  ORDERS_MOUDLE_TATUSES
} from '../../../constant/const'
import { timestampToDate } from '../../../utils/time'

export default {
  props: {
    ...PROPS_ID
  },
  data() {
    return {
      total: 0,
      pageNum: 1,
      orderList: [],
      orderStatus: ORDERS_MOUDLE_TATUSES,
      serviceStatus: SERVICE_STATUS,
      urgent: URGENT,
      loading: true,
      types: [],
      typesMap: [],
      queryParams: { ...ASSOC_SEARCH_BY_USER }
    }
  },

  created() {
    // listType(this).then((res) => {
    //   let types = []
    //   res.forEach(element => {
    //     types.push({
    //       id: element.id,
    //       typeName: element.typeName
    //     })
    //   });

    //   this.typesMap = types
    // })
  },

  mounted() {

  },

  watch: {
    id: {
      handler: function (value) {

        if (0 >= value) {
          return;
        }

        this.queryParams.id = value;

        this.getList()
      },
      immediate: true
    }
  },

  methods: {
    timestampToDate,
    getList() {
      listOrderByUserId(this.queryParams).then((res) => {
        console.log('res data', res)
        this.loading = false
        this.total = res.total
        this.orderList = res.rows

        for (let i = 0; i < this.orderList.length; i++) {
          this.orderList[i].createTime = timestampToDate(
            this.orderList[i].createTime
          )
        }
      })
    }
  },
  computed: {
    serviceTypes() {
      return (id) => {
        let type = this.typesMap.length && this.typesMap.find(item => item.id === id)
        return type ? type.typeName : ''
      }
    }
  }
}
</script>

<style></style>
